package com.hoshiibuy.company.controller;

import com.hoshiibuy.company.service.ICompanyLoginService;
import com.hoshiibuy.company.entity.ComOrganization;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 公司登陆 前端控制器
 * </p>
 *
 * @author WGJ
 * @since 2019-04-20
 */
@RestController
@RequestMapping("/companyLogin")
@Api(value = "机构注册登陆", tags = {"机构注册登陆操作接口"})
public class CompanyLoginController {
    private final Logger LOGGER = LoggerFactory.getLogger(CompanyController.class);


    @Autowired
    ICompanyLoginService companyLoginService;

    @RequestMapping(value = "/register", method = RequestMethod.POST)
    @ApiOperation(
            value = "注册公司",
            notes = "在saas平台注册公司",
            produces = "application/json, application/xml",
            consumes = "application/json, application/xml")
    public void registerCompany(@Valid ComOrganization comOrganization) {

        companyLoginService.registerCompany(comOrganization);
    }

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    @ApiOperation(
            value = "公司登陆",
            notes = "通过用户名和密码登陆",
            produces = "application/json, application/xml",
            consumes = "application/json, application/xml")
    @CacheEvict(cacheNames = "companyLogin", allEntries = true)
    public boolean companyLogin(String UserName, String password) {

        return companyLoginService.companyLogin(UserName, password);
    }

    @RequestMapping(value = "/loginByphoneNo", method = RequestMethod.GET)
    @ApiOperation(
            value = "公司登陆",
            notes = "通过短信验证码登陆",
            produces = "application/json, application/xml",
            consumes = "application/json, application/xml")
    public boolean companyLoginByPhoneNo(String phoneNo, String securityCode) {
        return companyLoginService.companyLoginByPhoneNo(phoneNo, securityCode);
    }

}
